// @Author EthanScriptOn
// @Desc
package custom_exp

import (
	"fmt"
	"gitee.com/fatzeng/srf_switch_basic_components/util"
	"time"
)

const FRAMEWORK_TEMPLATE = "Error with \r\n\t%s\r\n Occurred at \n\t(%s)\n Error at \n%s\n"

// SrfSwitchError Frame custom exceptions, format output for exceptions
type SrfSwitchError struct {
	msg      string
	position string
	time     time.Time
}

func (s SrfSwitchError) Error() string {
	return fmt.Sprintf(FRAMEWORK_TEMPLATE, s.msg, s.time.Format(time.RFC3339), s.position)
}

func (s *SrfSwitchError) SetPosition(position string) {
	s.position = position
}

func (s *SrfSwitchError) GetPosition() string {
	return s.position
}

func (s *SrfSwitchError) SetMsg(msg string) {
	s.msg = msg
}

func (s *SrfSwitchError) GetMsg() string {
	return s.msg
}

func GenerateSrfSwitchError(msg string, position string) *SrfSwitchError {
	return &SrfSwitchError{
		msg:      msg,
		position: position,
		time:     time.Now(),
	}
}

func GenerateSimpleSrfSwitchError(msg string) *SrfSwitchError {
	return &SrfSwitchError{
		msg:      msg,
		position: util.GetPosition(4),
		time:     time.Now(),
	}
}
